<?php global $base_url; ?>
<?php if ($data['order_confirm']->rowCount() > 0): ?>
<?php $total_price = 0; ?>
<form action="<?php print $base_url . '/packages/do_payment';?>" method="POST" name="form_packages_payment">
    <div class="cal-form-item">
        <h2>Packages</h2>
        <ul class="confirm-payment-items">
            <?php foreach ($data['order_confirm'] as $order): ?>
            <li>
                <?php $package_price = 0;$package_storage_fee = 0;?>
                <fieldset>
                    <legend><label><?php print tvn_generate_order_id($order->oid);?></label></legend>
                    <?php $options = unserialize($order->options);?>
                    <?php $items = node_load_multiple(explode(',', $order->nids));?>
                    <?php $total_ser_fee = 0;?>
                    <?php foreach ($items as $item): ?>
                    <div class="cart-item payment-item">
                        <div class="cart-left item-img">
                            <?php $img_uri = !empty($item->field_images[LANGUAGE_NONE][0]['uri'])
                                ? $item->field_images[LANGUAGE_NONE][0]['uri'] : '';?>
                            <?php print theme('image_style', array('path' => $img_uri, 'style_name' => 'crop_65x65'));?>
                        </div>
                        <div class="cart-right">
                            <div class="cart-info">
                                <div class="item-name"><h3><?php print l($item->title, 'node/' . $item->nid);?></h3>
                                </div>
                            </div>
                            <div class="cart-options package-options">
                                <?php
                                $package = node_load($item->field_item_package[LANGUAGE_NONE][0]['nid']);
                                $op_html = '';
                                if (!empty($options['item_services'][$item->nid])) {
                                    foreach ($options['item_services'][$item->nid] as $sid) {
                                        $service = taxonomy_term_load($sid);
                                        if ($service) {
                                            $ser_fee = 0;
                                            if (!empty($service->field_service_price[LANGUAGE_NONE][0]['value'])) {
                                                $ser_fee = number_format($service->field_service_price[LANGUAGE_NONE][0]['value'], 2);
                                                $total_ser_fee += $ser_fee;
                                            }
                                            $op_html .= '<p><strong>' . $service->name . '</strong>' . ($ser_fee
                                                    ? ' - $' . $ser_fee
                                                    : ' - Free') . '</p>';
                                        }
                                    }
                                }
                                $storage_fee = tvn_order_calculator_price_storage_item($package->field_date_received[LANGUAGE_NONE][0]['value']);
                                if ($storage_fee) {
                                    $op_html .= '<p><strong>Storage Fee - </strong>' . '$' . $storage_fee . '</p>';
                                    $total_ser_fee += $storage_fee;
                                    $package_storage_fee += $storage_fee;
                                }

                                print $op_html;
                                ?>
                            </div>
                        </div>
                        <div class="clear"></div>
                    </div>
                    <?php endforeach;?>
                    <div class="order-fee">
                        <h4>Shipping
                            Method: <?php print $options['shipping_method']['name'] . ' - $' . $options['shipping_method']['fee'];?></h4>
                        <?php print _tvn_common_optional_service_html($options, ($total_ser_fee + $options['shipping_method']['fee']));?>
                        <?php $package_fee = tvn_order_calculator_price_order($options, $order->nids) + $package_storage_fee;?>
                        <?php $total_price += $package_fee;?>
                        <h4 class="package-fee">Package Fee: <?php print '$' . number_format($package_fee, 2)?></h4>
                    </div>
                </fieldset>
            </li>
            <?php endforeach;?>
        </ul>
        <h2>Total Fee: <?php print '$' . number_format($total_price, 2);?></h2>
        <input type="hidden" name="packages_price" value="<?php print number_format($total_price, 2);?>"/>
        <?php $_SESSION['packages_price'] = number_format($total_price, 2);?>
        <input type="hidden" name="packages_id" value="<?php print $data['oids'];?>"/>
    </div>
    <div class="form-actions">
        <input type="submit" name="submit" value="Confirm Payment" class="btn btn-primary"/>
        <a href="<?php print $base_url . '/home#purchaseable_consolidations-tab'?>" title="Cancel Payment" class="btn">
            Cancel
        </a>
    </div>
</form>
<?php endif; ?>